/*
* @Author: wangliang
* @Date: 2018/4/10
* @description: 基本信息
*/
<template>
    <div>
        <el-row class="custom-title m-t-20 m-b-20">
            <h3>基本信息
                <span class="m-l-20">最后更新时间：{{modifyTime | cmsMoment}}</span>
                <el-button type="primary" size="mini" round class="m-l-20" @click="save(infoStatus, publicMessage, true)">保存</el-button>
                <el-dropdown trigger="click" @command="chooseOperate">
                    <el-button type="primary" plain>{{operateStatus}}<i class="el-icon-arrow-down el-icon--right"></i></el-button>
                    <el-dropdown-menu slot="dropdown">
                        <el-dropdown-item 
                        v-for="(item, i) in operateStatusList"
                        :key="i"
                        :command="item.dictName"
                        >{{item.dictName}}</el-dropdown-item>
                    </el-dropdown-menu>
                </el-dropdown>
            </h3>
        </el-row>
        <el-form class="custom-box p-20" :rules="rules" :model="companyDetails" ref="basicForm">
            <el-row>
                <el-col :span="11">
                    <el-form-item label="企业名称" label-width="90px" prop="fullName">
                        <el-autocomplete
                            :maxlength="50"
                            style="width:100%"
                            v-model="companyDetails.fullName"
                            :fetch-suggestions="getSearchTitle"
                            placeholder="请输入内容"
                            :trigger-on-focus="false"
                            @select="handleSelect"
                        ></el-autocomplete>
                        <!-- <el-input placeholder="请输入名称" v-model="companyDetails.fullName" :maxlength="50"></el-input> -->
                    </el-form-item>
                    <el-form-item label="企业简称" label-width="90px">
                        <el-input placeholder="请输入名称" v-model="companyDetails.shortName" :minlength='2' :maxlength='7'></el-input>
                    </el-form-item>
                    <el-form-item label="历史曾用名" label-width="90px">
                        <el-row :gutter="5" v-for="(item, index) in historyName" :key="index">
                            <el-col :span='7'>
                                <el-date-picker
                                v-model="item.onceStartTime"
                                type="date"
                                placeholder="选择日期"
                                style="width:100%">
                                </el-date-picker>
                            </el-col>
                            <el-col :span='7'>
                                <el-date-picker
                                v-model="item.onceEndTime"
                                type="date"
                                placeholder="选择日期"
                                style="width:100%">
                                </el-date-picker>
                            </el-col>
                            <el-col :span='8'>
                                <el-input placeholder="请输入名称" v-model="item.onceName" style="width:100%" :maxlength="50"></el-input>
                            </el-col>
                            <el-col :span='1'>
                                <button type="button" class="custom-btn custom-btn-round" @click="addHistoryName" v-if="index==0">
                                    <i class="fa fa-plus"></i>
                                </button>
                                <button type="button" class="custom-btn custom-btn-round" @click="delHistoryName(index)" v-else>
                                    <i class="fa fa-remove"></i>
                                </button>
                            </el-col>
                        </el-row>
                    </el-form-item>
                    <el-form-item label="国际化名称" label-width="90px">
                        <el-input v-model="companyDetails.intFullName" :maxlength="50"></el-input>
                    </el-form-item>
                    <el-form-item label="国际化简称" label-width="90px">
                        <el-input v-model="companyDetails.intShortName" :maxlength="50"></el-input>
                    </el-form-item>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="成立时间" label-width="90px">
                                <el-date-picker
                                v-model="companyDetails.beginTime"
                                type="date"
                                placeholder="选择日期"
                                style="width:95%">
                                </el-date-picker>
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item label="天眼查ID" label-width="70px">
                                <el-input v-model="companyDetails.graphId"></el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-form-item label="国家" label-width="90px" prop="area">
                        <el-cascader
                        style="width:100%"
                        @change="testCountry"
                        v-model="companyDetails.area"
                        :options="areaList"
                        :filterable="true"
                        :clearable="true" />
                    </el-form-item>
                    <el-form-item label="注册地址" label-width="90px">
                        <el-input v-model="companyDetails.registerAddress"></el-input>
                    </el-form-item>
                    <el-form-item label="网址" label-width="90px">
                        <el-input v-model="companyDetails.webUrl"></el-input>
                    </el-form-item>
                    <el-form-item label="企业状态" label-width="90px">
                        <el-select v-model="companyDetails.comState" placeholder="请选择">
                            <el-option
                            v-for="(item, index) in dropDown.companyStatus"
                            :key="index"
                            :label="item.dictName"
                            :value="Number(item.dictValue)">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="Logo" label-width="90px">
                        <LogoImg
                        ref="logoImg"
                        @onSuccess="onSuccess"
                        :src='imgSrc' />
                    </el-form-item>
                    <el-form-item label="身份属性标示" label-width="100px">
                        <el-checkbox-group v-model="identityList" @change="controlFlag">
                            <el-checkbox v-for="(item, index) in dropDown.companyIdentityView" :label="item.dictName" :key="index" v-if="item.dictName !== '投行属性' && item.dictName !== '发布机构' && item.level == 1">{{item.dictName}}</el-checkbox>
                            <div class="position-r">
                                 <el-checkbox v-for="(item, index) in dropDown.companyIdentityView" :label="item.dictName" :key="index" v-if="item.dictName == '投行属性'">{{item.dictName}}</el-checkbox>
                                <div class="position-a" v-if="attributeFlag">
                                    <el-checkbox-group v-model="checkList" class="el-check" size="small" @change="bankAttached">
                                        <el-checkbox v-for="(itemLevel, ind) in dropDown.companyIdentityView" :key="ind" :label="itemLevel.dictName" v-if="itemLevel.level == 2" border>{{itemLevel.dictName}}</el-checkbox>
                                    </el-checkbox-group>
                                </div>
                            </div>
                            <div class="position-r">
                                <el-checkbox v-for="(item, index) in dropDown.companyIdentityView" :label="item.dictName" :key="index" v-if="item.dictName == '发布机构'">{{item.dictName}}</el-checkbox>
                                <div class="position-b" v-if="publisherFlag">
                                    <el-form-item label="发布机构类型" label-width="100px">
                                        <el-select v-model="companyDetails.publisherTypeAttr" placeholder="请选择" size="small">
                                            <el-option
                                            v-for="(item, index) in dropDown.publisherType"
                                            :key="index"
                                            :label="item.dictName"
                                            :value="Number(item.dictValue)"></el-option>
                                        </el-select>
                                    </el-form-item>
                                    <el-form-item label="推荐等级" label-width="100px">
                                        <el-select v-model="companyDetails.gradeAttr" placeholder="请选择" size="small">
                                            <el-option
                                            v-for="(item, index) in dropDown.recommendLevel"
                                            :key="index"
                                            :label="item.dictName"
                                            :value="Number(item.dictValue)"></el-option>
                                        </el-select>
                                    </el-form-item>
                                </div>
                            </div>
                        </el-checkbox-group>
                    </el-form-item>
                </el-col>
                <el-col :span="11" :offset="2">
                    <el-form-item label="CV行业分类" label-width="100px" prop="cvIndustryValue" >
                        <el-cascader
                        style="width:100%"
                        @change="testCV"
                        v-model="companyDetails.cvIndustryValue"
                        :options="cvIndustryListCascader"
                        :filterable="true"
                        :clearable="true" />
                    </el-form-item>
                    <el-form-item label="国标分类" label-width="100px" prop="csIndustryValue" >
                        <el-cascader
                        @change="csIndustryChange"
                        style="width:100%"
                        v-model="companyDetails.csIndustryValue"
                        :options="csIndustryListCascader"
                        :filterable="true"
                        :clearable="true" />
                    </el-form-item>
                    <el-form-item label="证监会分类" label-width="100px" prop="sfcIndustryValue" >
                        <el-cascader
                        style="width:100%"
                        @change="testSFC"
                        v-model="companyDetails.sfcIndustryValue"
                        :options="sfcIndustryListCascader"
                        :filterable="true"
                        :clearable="true" />
                    </el-form-item>
                    <el-form-item label="申银万国" label-width="100px" prop="snIndustryValue">
                        <el-cascader
                        style="width:100%"
                        @change="testSN"
                        v-model="companyDetails.snIndustryValue"
                        :options="snIndustryListCascader"
                        :filterable="true"
                        :clearable="true" />
                    </el-form-item>
                    <cmsTag :comTagDtoList="comTagDtoList" :cvIndustryValue="cvIndustryValue" :shouwAddTag="true" @tagPass='tagPass' :title="'标签组'" ref="tag" />
                    <el-form-item label="企业简介" label-width="100px">
                        <el-input type="textarea" :rows="8" resize="none" v-model="companyDetails.description"></el-input>
                    </el-form-item>
                    <el-form-item label="备注" label-width="100px">
                        <el-input type="textarea" :rows="8" resize="none" v-model="companyDetails.remark"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>    
        </el-form>
        <div v-if="showOther">
            <ListedInfo></ListedInfo>
            <ContactInfo></ContactInfo>
            <AssociationRelationship></AssociationRelationship>
            <ShareholderInfo></ShareholderInfo>
            <OutboundInvestment></OutboundInvestment>
        </div>
    </div>
</template>
<script lang="ts">
import Vue from 'vue';
import { Component, Watch } from 'vue-property-decorator';
import { CompanyDetailsDto, ComNameOnceDto, ComIndustryDto, ComTagDto } from '../../../../../api/Interface';
import { CompanyListSearchDto } from '../../../../../service/subject/company/companyInterface';
import BasicInfoService from '../../../../../service/subject/company/basic-info/index';
import ListService from '../../../../../service/subject/company/index';
import { getCascaderData, setFullValue, getIndustryById } from '../../../../../libs/utils';
import ListedInfo from './listed-info.vue';
import ContactInfo from './contact-info.vue';
import AssociationRelationship from './association-relationship.vue';
import ShareholderInfo from './shareholder-info.vue';
import OutboundInvestment from './outbound-investment.vue';
import cmsTag from '../../../../../components/cms-tag/index.vue';
import LogoImg from '../../../../../components/logo/index.vue';
interface Industry {
  children: Industry[];
  code: string;
  level: number;
  name: string;
  parentCode: string;
}
interface CompanyInfo extends CompanyDetailsDto {
    area: number[]; // 国家
    cvIndustryValue: string[]; // cv行业
    csIndustryValue: string[]; // 国标
    sfcIndustryValue: string[]; // 证监会
    snIndustryValue: string[]; // 申银万国
}
interface Result {
    value: string;
    id: number;
}
@Component({
    components: {
        cmsTag, // 标签
        LogoImg, // Logo
        ListedInfo, // 上市信息
        ContactInfo, // 联系方式
        AssociationRelationship, // 关联关系
        ShareholderInfo, // 股东信息
        OutboundInvestment, // 对外投资
    }
})
export default class BasicInfo extends Vue {
    // 初始化数据 相当于data
    // public msg: number = 123;
    public companyListSearch: CompanyListSearchDto = {nameType: 'full_name'} as CompanyListSearchDto;
    public companyDetails: CompanyInfo = {} as CompanyInfo; // <PersonVo> {}
    public comNameOnce: ComNameOnceDto  = {} as ComNameOnceDto; // 企业历史曾用名
    public industryList: ComIndustryDto[] = []; // 行业信息
    public modifyTime: number = (new Date()).valueOf();
    public imgSrc: string = ''; // 图片
    public result: Array<Result> = []; // 模糊查询结果callBack参数
    public infoStatus: string = '0000';
    public publicMessage: string = '';
    public tip: boolean = false;
    public tags: boolean;
    public cvIndustryValue: string[] = [];
    public showOther: boolean = false;
    public companyId: number = 0;
    public dropDown: object = {
        publisherType: this.$store.state.user.dictionary.dicList.publisherType, // 发布机构类型
        recommendLevel: this.$store.state.user.dictionary.dicList.recommendLevel, // 推荐等级
        companyIdentityView: this.$store.state.user.dictionary.dicList.companyIdentityView, // 身份标识
        companyStatus: this.$store.state.user.dictionary.dicList.companyStatus, // 企业状态
    };
    public operateStatus: string = '运营标记';
    public operateStatusList: object[] = [
        {
            dictValue: 1,
            dictName: '运营'
        },
        {
            dictValue: 2,
            dictName: '不运营'
        },
    ];
    // 国家
    public areaList = getCascaderData({data: this.$store.state.user.dictionary.dicAreaList, name: 'cnName', key: 'id'});
    // public area: number[] = [];
    // cv行业
    public cvIndustryList = this.$store.state.user.dictionary.cvIndustryList;
    public cvIndustryListCascader = getCascaderData( {data: this.cvIndustryList} );
    // public cvIndustryValue: string[] = [];
    // 国标
    public csIndustryList = this.$store.state.user.dictionary.csIndustryList;
    public csIndustryListCascader = getCascaderData( {data: this.csIndustryList} );
    // public csIndustryValue: string[] = [];
    // 证监会
    public sfcIndustryList = this.$store.state.user.dictionary.sfcIndustryList;
    public sfcIndustryListCascader = getCascaderData( {data: this.sfcIndustryList} );
    // public sfcIndustryValue: string[] = [];
    // 申银万国
    public snIndustryList = this.$store.state.user.dictionary.snIndustryList;
    public snIndustryListCascader = getCascaderData( {data: this.snIndustryList} );
    public checkList: string[] = [];
    public identityList: string[] = []; // 身份属性
    public publisherFlag: boolean = false; // 发布机构
    public attributeFlag: boolean = false; // 投行属性
    public basicOperate: number = 0; //企业基本信息运营标记
    public historyName: ComNameOnceDto[] = [
        {
            companyId: 0,     //企业id
            onceEndTime: '',         //曾用名称结束时间
            onceStartTime: '',         //曾用名称开始时间
            id: 0,         //主id
            onceName: '',         //曾用名称',
        },
    ]; // 历史曾用名
    public historyNameInfo: ComNameOnceDto = {
        companyId: 0,     //企业id
        onceEndTime: '',         //曾用名称结束时间
        onceStartTime: '',         //曾用名称开始时间
        id: 0,         //主id
        onceName: '',         //曾用名称',
    };
    // 标签 列表
    public comTagDtoList: ComTagDto[] = [];
    public rules = {
        fullName: [ { required: true, message: '请输入企业名称', trigger: 'blur' } ],
        area: [ { required: true, validator: this.validatePass, trigger: 'change' } ],
        cvIndustryValue: [ { required: true, validator: this.validatePass2, trigger: 'change' } ],
        csIndustryValue: [ { required: true, validator: this.validatePass2, trigger: 'change' } ],
        sfcIndustryValue: [ { required: true, validator: this.validatePass2, trigger: 'change' } ],
        snIndustryValue: [ { required: true, validator: this.validatePass2, trigger: 'change' } ],
    };
    public disabledList: boolean[] = [];
    // refs
    public $refs: {
        basicForm: HTMLFormElement,
        tag: any,
        logoImg: any
    };

    // watch
    @Watch('companyDetails.fullName')
    public fullName(val: string, oldVal: string) {
        if (this.companyDetails.fullName) {
            this.disabledList[0] = true;
            this.testNotice();
        } else {
            this.disabledList[0] = false;
            this.testNotice();
        }
    }

    // 声明周期钩子
    public mounted() {
        if (this.$route.params.itemId !== '-1') {
            this.companyId = Number(this.$route.params.itemId);
            this.showOther = true;
            // this.getBasicInfo(Number(this.companyId));
        } else {
            this.companyId = 0;
        }
    }
    // 方法
    // 更改运营标记
    public chooseOperate(command: string) {
        this.operateStatus = command;
        if (command === '运营') {
            this.basicOperate = 1;
        } else if (command === '不运营') {
            this.basicOperate = 2;
        }
    }
    // 中文名称模糊查询
    public async getSearchTitle(queryString: string, cb: any) {
        this.companyListSearch['pageParam.pageIndex'] = 1;
        this.companyListSearch['pageParam.pageSize'] = 100;
        this.companyListSearch.attributeStatus = '1';
        this.companyListSearch.name = queryString;
        const res = await ListService.companyPage(this.companyListSearch);
        if (res.resCode === '0') {
            const searchList = res.data.resultData;
            const result = searchList.map((item: any) => {
            return { value: item.fullName, id: item.id };
            });
            cb(result);
        }
    }
    // 模糊查询带出详情 
    public handleSelect(item: Result) {
        this.$router.replace({ name: 'company-detail', params: { itemId: item.id.toString(), tabIndex: '0'}});      
        this.getBasicInfo(item.id);
    }
    // 控制发布机构和投行属性显隐  
    public controlFlag() {
        if (this.identityList.indexOf('发布机构') >= 0) {
            this.publisherFlag = true;
            this.companyDetails.publisherAttr = 1;
        } else {
            this.publisherFlag = false;
            this.companyDetails.publisherAttr = 2;
        }
        if (this.identityList.indexOf('投行属性') >= 0) {
            this.attributeFlag = true;
            this.companyDetails.investmentAttr = 1;
        } else {
            this.attributeFlag = false;
            this.checkList = [];
            this.companyDetails.investmentAttr = 2;
        }
        if (this.identityList.indexOf('机构属性') >= 0) {
            this.companyDetails.orgAttr = 1;
        } else {
            this.companyDetails.orgAttr = 2;
        }
        if (this.identityList.indexOf('基金属性') >= 0) {
            this.companyDetails.fundAttr = 1;
        } else {
            this.companyDetails.fundAttr = 2;
        }
        if (this.identityList.indexOf('LP属性') >= 0) {
            this.companyDetails.lpAttr = 1;
        } else {
            this.companyDetails.lpAttr = 2;
        }
        if (this.identityList.indexOf('交易所') >= 0) {
            this.companyDetails.exchangeAttr = 1;
        } else {
            this.companyDetails.exchangeAttr = 2;
        }
        if (this.identityList.indexOf('会所属性') >= 0) {
            this.companyDetails.accountantAttr = 1;
        } else {
            this.companyDetails.accountantAttr = 2;
        }
        if (this.identityList.indexOf('律所属性') >= 0) {
            this.companyDetails.lawinstituteAttr = 1;
        } else {
            this.companyDetails.lawinstituteAttr = 2;
        }
        if (this.identityList.indexOf('托管银行') >= 0) {
            this.companyDetails.trusteeBankAttr = 1;
        } else {
            this.companyDetails.trusteeBankAttr = 2;
        }
        if (this.identityList.indexOf('评估公司') >= 0) {
            this.companyDetails.appraiseAttr = 1;
        } else {
            this.companyDetails.appraiseAttr = 2;
        }
        // 身份标识控制tab
        this.$emit('tabCon', this.identityList);
    }
    // 投行属性附属
    public bankAttached() {
        if (this.checkList.indexOf('新型投行') >= 0) {
            this.companyDetails.newInvestmentAttr = 1;
        } else {
            this.companyDetails.newInvestmentAttr = 2;
        }
        if (this.checkList.indexOf('承销商') >= 0) {
            this.companyDetails.underwriterAttr = 1;
        } else {
            this.companyDetails.underwriterAttr = 2;
        }
        if (this.checkList.indexOf('保荐资格') >= 0) {
            this.companyDetails.bankAttr = 1;
        } else {
            this.companyDetails.bankAttr = 2;
        }
    }
    // 反显身份标识
    public showIdentity(info: CompanyDetailsDto) {
        this.identityList = [];
        this.checkList = [];
        if (info.publisherAttr === 1) {
            this.identityList.push('发布机构');
            this.publisherFlag = true;
        }
        if (info.investmentAttr === 1) {
            this.identityList.push('投行属性');
            this.attributeFlag = true;
            if (info.newInvestmentAttr === 1) {
                this.checkList.push('新型投行');
            }
            if (info.underwriterAttr === 1) {
                this.checkList.push('承销商');
            }
            if (info.bankAttr === 1) {
                this.checkList.push('保荐资格');
            }
        }
        if (info.orgAttr === 1) {
            this.identityList.push('机构属性');
        }
        if (info.fundAttr === 1) {
            this.identityList.push('基金属性');
        }
        if (info.lpAttr === 1) {
            this.identityList.push('LP属性');
        }
        if (info.exchangeAttr === 1) {
            this.identityList.push('交易所');
        }
        if (info.accountantAttr === 1) {
            this.identityList.push('会所属性');
        }
        if (info.lawinstituteAttr === 1) {
            this.identityList.push('律所属性');
        }
        if (info.trusteeBankAttr === 1) {
            this.identityList.push('托管银行');
        }
        if (info.appraiseAttr === 1) {
            this.identityList.push('评估公司');
        }
    }
    // 添加历史曾用名
    public addHistoryName() {
        this.historyName.push(Object.assign({}, this.historyNameInfo));
    }
    // 删除历史曾用名
    public delHistoryName(index: number) {
        this.historyName.splice(index, 1);
    }
    // 图片上传
    public onSuccess(imgId: string) {
        if (imgId) {
            this.companyDetails.logo = imgId;
        }
        if (this.basicOperate === 0 || this.basicOperate === 2 || this.basicOperate === null || this.basicOperate === undefined ) {
            this.$message.error('请选择运营标记为运营时才能保存！');
        } else {
            this.controlFlag();
            this.bankAttached();
            this.$refs.basicForm.validate(async ( valid: boolean) => {
                if (valid) {
                    // 验证投资标签是否 有值
                    const tagValid = await this.$refs.tag.checkInput();
                    if (!tagValid) {
                        this.$message.error('请完善信息');
                        return;
                    }
                    const tagList = await this.$refs.tag.getTagList();
                    // 标签
                    this.companyDetails.tagList = tagList;
                    // 处理国家
                    this.companyDetails.area.map( (item: number, index: number) => {
                        if (index === 0) { // 国家
                            this.companyDetails.country = item;
                        } else if (index === 1) { // 省
                            this.companyDetails.province = item;
                        } else if (index === 2) { // 市
                            this.companyDetails.city = item;
                        }
                    });
                    // 处理行业
                    if (this.companyDetails.cvIndustryValue.length > 0) { // CV行业分类
                        this.industryList.push(this.industryChange(this.cvIndustryList, this.companyDetails.cvIndustryValue, 1));
                    }
                    if (this.companyDetails.csIndustryValue.length > 0) { // 国标分类
                        this.industryList.push(this.industryChange(this.csIndustryList, this.companyDetails.csIndustryValue, 2));
                    }
                    if (this.companyDetails.sfcIndustryValue.length > 0) { // 证监会分类
                        this.industryList.push(this.industryChange(this.sfcIndustryList, this.companyDetails.sfcIndustryValue, 3));
                    }
                    if (this.companyDetails.snIndustryValue.length > 0) { // 申银万国
                        this.industryList.push(this.industryChange(this.snIndustryList, this.companyDetails.snIndustryValue, 4));
                    }
                    // 行业信息
                    this.companyDetails.industryList = this.industryList;
                    const historyList: ComNameOnceDto[] = [];
                    this.historyName.map( (item: ComNameOnceDto) => {
                        if (item.onceEndTime || item.onceStartTime || item.onceName) {
                            historyList.push(item);
                        }
                    });
                    this.companyDetails.nameOnce = historyList;
                    // 企业基本信息运营
                    this.companyDetails.basicOperate = this.basicOperate;
                    this.saveInfo(this.tip);
                } else {
                    this.$message.error('请完善信息');
                }
            });
        }
    }
    // 保存按钮
    public save(infoStatus: string, publicMessage: string, tip: boolean, operate: number) {
        if (operate) {
            this.basicOperate = operate;
        }
        this.companyDetails.infoStatus = infoStatus;
        this.companyDetails.publishMessage = publicMessage;
        this.tip = tip;
        this.$refs.logoImg.up();
    }
    // 保存
    public async saveInfo(tip: boolean) {
        const companySave = JSON.parse(JSON.stringify(this.companyDetails));
        delete companySave.area;
        delete companySave.cvIndustryValue; // cv行业
        delete companySave.csIndustryValue; // 国标
        delete companySave.sfcIndustryValue; // 证监会
        delete companySave.snIndustryValue; // 申银万国
        if (this.$route.params.itemId !== '-1') { // 修改
            if (this.companyDetails.competitorOperate === null) {
                companySave.competitorOperate = 2;
            }
            if (this.companyDetails.businessOperate === null) {
                companySave.businessOperate = 2;
            }
            if (this.companyDetails.productOperate === null) {
                companySave.productOperate = 2;
            }
            const res = await BasicInfoService.updateCompany(companySave);
            if (res.resCode === '0') {
                await this.getBasicInfo(Number(this.companyId));
                if (tip) {
                    this.$message.success('修改成功');
                    this.$emit('updateIdentification');
                }
            }
        } else if (this.$route.params.itemId === '-1') { // 添加
            // 设置其他信息运营
            companySave.competitorOperate = 2;
            companySave.businessOperate = 2;
            companySave.productOperate = 2;
            const res = await BasicInfoService.saveCompany(companySave);
            if (res.resCode === '0') {
                if (tip) {
                    this.$message.success('添加成功');
                    this.$emit('updateIdentification');
                }
                this.companyId = res.data;
                this.$router.replace({name: 'company-detail', params: {itemId: res.data}});
            }
        }
        this.showOther = true;
    }
    // 获取基本信息
    public async getBasicInfo(id: number) {
        const res = await BasicInfoService.getCompanyById(id);
        if (res.resCode === '0') {
            this.companyDetails = res.data;
            this.basicOperate = this.companyDetails.basicOperate;
            this.imgSrc = res.data.ossPhotoUrl;
            if (this.basicOperate === 1) {
                this.operateStatus = '运营';
            }
            if (this.basicOperate === 2) {
                this.operateStatus = '不运营';
            }
            // 国家处理
            this.companyDetails.area = [];
            if (res.data.country || res.data.province || res.data.city) {
                // this.companyDetails.area = [];
                this.companyDetails.area[0] = res.data.country;
                this.companyDetails.area[1] = res.data.province;
                if (res.data.city) {
                    this.companyDetails.area[2] = res.data.city;
                }
            }
            this.companyDetails.sfcIndustryValue = [];
            this.companyDetails.snIndustryValue = [];
            this.companyDetails.csIndustryValue = [];
            this.companyDetails.cvIndustryValue = [];
            // 行业处理
            if (res.data.industryList.length > 0) {
                // this.companyDetails.sfcIndustryValue = [];
                // this.companyDetails.snIndustryValue = [];
                // this.companyDetails.csIndustryValue = [];
                // this.companyDetails.cvIndustryValue = [];
                res.data.industryList.map((item: ComIndustryDto) => {
                    if (item.industryType === 1) { // cv行业标签
                        this.companyDetails.cvIndustryValue[0] = item.oneLevel;
                        this.companyDetails.cvIndustryValue[1] = item.twoLevel;
                        if (item.threeLevel) {
                            this.companyDetails.cvIndustryValue[2] = item.threeLevel;
                        }
                    } else if (item.industryType === 2) { // 国标分类
                        this.companyDetails.csIndustryValue[0] = item.oneLevel;
                        this.companyDetails.csIndustryValue[1] = item.twoLevel;
                        if (item.threeLevel) {
                            this.companyDetails.csIndustryValue[2] = item.threeLevel;
                        }
                    } else if (item.industryType === 3) { // 证监会分类
                        this.companyDetails.sfcIndustryValue[0] = item.oneLevel;
                        this.companyDetails.sfcIndustryValue[1] = item.twoLevel;
                        if (item.threeLevel) {
                            this.companyDetails.sfcIndustryValue[2] = item.threeLevel;
                        }
                    } else if (item.industryType === 4) { // 申银万国
                        this.companyDetails.snIndustryValue[0] = item.oneLevel;
                        this.companyDetails.snIndustryValue[1] = item.twoLevel;
                        if (item.threeLevel) {
                            this.companyDetails.snIndustryValue[2] = item.threeLevel;
                        }
                    }
                });
                this.cvIndustryValue = this.companyDetails.cvIndustryValue;
            }
            this.comTagDtoList = res.data.tagList;
            if (this.companyDetails.nameOnce.length > 0) {
                this.historyName = this.companyDetails.nameOnce;
            }
            this.infoStatus = res.data.infoStatus;
            this.publicMessage = res.data.publishMessage;
            this.modifyTime = res.data.modifyTime;
            this.showIdentity(this.companyDetails);
            // 基本信息tab
            if (!res.data.fullName || !res.data.country || res.data.industryList.length <= 0 || res.data.tagList.length <= 0 ) {
                this.$emit('basicTest', false);
            } else {
                this.$emit('basicTest', true);
            }
            res.data.fullName === '' ? this.disabledList[0] = false : this.disabledList[0] = true; // 企业名称
            this.companyDetails.area.length === 0 ? this.disabledList[1] = false : this.disabledList[1] = true; // 国家
            this.companyDetails.cvIndustryValue.length === 0 ? this.disabledList[2] = false : this.disabledList[2] = true; // cv行业
            this.companyDetails.csIndustryValue.length === 0 ? this.disabledList[3] = false : this.disabledList[3] = true; // 国标
            this.companyDetails.sfcIndustryValue.length === 0 ? this.disabledList[4] = false : this.disabledList[4] = true; // 证监会
            this.companyDetails.snIndustryValue.length === 0 ? this.disabledList[5] = false : this.disabledList[5] = true; // 申银万国
            res.data.tagList.length === 0 ? this.disabledList[6] = false : this.disabledList[6] = true; // 标签
            this.testNotice();
            if (!this.disabledList[6]) {
                 // 验证投资标签是否 有值
                const tagValid = await this.$refs.tag.checkInput();
                if (!tagValid) {
                    return;
                }
            }
        }
    }
    // 根据国标分类 带出 证监会和申银万国的数据
    public csIndustryChange(value: string[]) {
        const lastVal = value[value.length - 1];
        // 带出证监会行业
        const sfcCode = getIndustryById(lastVal, setFullValue(this.csIndustryList), 'sfcCode');
        const sfcFullValue = getIndustryById(sfcCode, setFullValue(this.sfcIndustryList), 'fullValue');
        const sfcIndustryValue = sfcFullValue ? sfcFullValue.split('-') : [];
        // 带出证监会行业 end
        // 带出申银万国行业
        const snCode = getIndustryById(lastVal, setFullValue(this.csIndustryList), 'snCode');
        const snFullValue = getIndustryById(snCode, setFullValue(this.snIndustryList), 'fullValue');
        const snIndustryValue = snFullValue ? snFullValue.split('-') : [];
        this.companyDetails = {
            ...this.companyDetails,
            sfcIndustryValue,
            snIndustryValue
        };
        // 带出申银万国行业 end
        if (value.length === 0) {
            this.disabledList[3] = false;
            this.disabledList[4] = false;
            this.disabledList[5] = false;
            this.testNotice();
        } else {
            this.disabledList[3] = true;
            this.disabledList[4] = true;
            this.disabledList[5] = true;
            this.testNotice();
        }
    }
    // 行业转化
    public industryChange(mapObj: object[], mapArr: string[], type: number) {
        const comIndustry = {} as ComIndustryDto;
        comIndustry.industryType = type;
        mapObj.map( (item: Industry) => {
            if (item.code === mapArr[0]) {
                comIndustry.oneLevel = item.code;
                comIndustry.oneLevelName = item.name;
                if (item.children.length > 0) {
                    if (item.children) {
                        item.children.map( (childItem: Industry) => {
                            if (childItem.code === mapArr[1] ) {
                                comIndustry.twoLevel = childItem.code;
                                comIndustry.twoLevelName = childItem.name;
                                if (childItem.children.length > 0) {
                                    childItem.children.map( (grandSonItem: Industry) => {
                                        if (grandSonItem.code === mapArr[2]) {
                                            comIndustry.threeLevel = grandSonItem.code;
                                            comIndustry.threeLevelName = grandSonItem.name;
                                        }
                                    });
                                }
                            }
                        });
                    }
                }
            }
        });
        return comIndustry;
    }
    // 控制tab
    public testCountry() {
        // 国家
        if (this.companyDetails.area.length === 0 ) {
            this.disabledList[1] = false;
            this.testNotice();
        } else {
            this.disabledList[1] = true;
            this.testNotice();
        }
    }
    public testCV() {
        // cv行业
        if (this.companyDetails.cvIndustryValue.length === 0) {
            this.disabledList[2] = false;
            this.testNotice();
        } else {
            this.disabledList[2] = true;
            this.testNotice();
        }
        this.cvIndustryValue = this.companyDetails.cvIndustryValue;
    }
    public testSFC() {
        // 证监会
        if (this.companyDetails.sfcIndustryValue.length === 0) {
            this.disabledList[4] = false;
            this.testNotice();
        } else {
            this.disabledList[4] = true;
            this.testNotice();
        }
    }
    public testSN() {
        // 申银万国
        if (this.companyDetails.snIndustryValue.length === 0) {
            this.disabledList[5] = false;
            this.testNotice();
        } else {
            this.disabledList[5] = true;
            this.testNotice();
        }
    }
    // 标签验证
    public async tagPass(bool: boolean) {
        this.disabledList[6] = bool;
        this.testNotice();
    }
    // 验证通知
    public testNotice() {
        if (this.disabledList.indexOf(false) >= 0) {
            this.$emit('basicTest', false);
        } else {
            this.$emit('basicTest', true);
        }
    }
    // 检验
    public validatePass(rule: object, value: number[], callback: (obj ?: object) => void) {
        if (value && value.length !== 0) {
            value.map( (item: any) => {
                if (item === null) {
                    value = [];
                }
            });
        }
        if (value && value.length !== 0) {
            callback();
        } else {
            callback(new Error('请选择'));
        }
    }
    public validatePass2(rule: object, value: string[], callback: (obj ?: object) => void) {
        if (value && value.length !== 0) {
            callback();
        } else {
            callback(new Error('请选择'));
        }
    }

}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.wid-100 {
    width: 100%;
}
.ca-title {
    height: 36px;
    overflow: hidden;
}
.ca-title h3{
    font-weight: normal;
    font-size: 18px;
    color: #333333;
    float: left;
}
.line-h {
    line-height: 36px;
}
.addBtn {
    font-size: 20px;
    margin-top: 12px;
}
.el-checkbox{
    margin-right: 10px;
}
.el-checkbox {
    color: #606266;
    font-size: 14px;
    cursor: pointer;
    user-select: none;
    margin-left: 10px;
}
.position-r {
    position: relative;
}
.position-a {
    position: absolute;
    right: -100px;
    top: 5px;
}
.position-b {
    position: absolute;
    right: -40px;
    top: 0px;
}
.position-a .el-check{
    display:flex;
}
.minheight{
  height: 250px;
  overflow-y: auto;
  padding: 0 10px;
  border-radius: 5px;
}
.ca-box {
    background: #fff;
    border: #dbe3ea 1px solid;
}
.status-btn {
  position: relative;
}
.info-status {
  position:absolute;
  top: 40px;
  width: 90px;
  height: auto;
  text-align: center;
  z-index: 999;
}
.info-status .el-button {
  margin-left: 0px;
  margin-top: 10px;
}
</style>
